package com.ptu.util;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;
public class LoginInterceptor implements HandlerInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 1. 判断是否需要拦截（ThreadLocal中是否有用户）
        if (UserHolder.getUser() == null) {
            //System.out.println("登录拦截器：" + UserHolder.getUser());
            //response.setStatus(401);
            // 无用户拦截
            return false;
        }
        //System.out.println(UserHolder.getUser());
        // 有用户放行
        return true;
    }
}
